package com.rw.admin.controller;

import org.springframework.core.Constants;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(ConstraintViolationException.class)
    @ResponseBody
    public Map<String, Object> AriExceptioin(ConstraintViolationException e){
        Map<String, Object> map =new HashMap<>();
        String msg ="";
        for (ConstraintViolation item:e.getConstraintViolations()){
            msg+=item.getMessage()+",";
        }        map.put("code",198);
        map.put("msg","参数校验失败,"+msg);
        return map;
    }



}
